 <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html"%>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic"%>
<%@ taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles"%>
<%@ taglib uri="jstl-fn" prefix="fn" %>
<%@ taglib prefix="c" uri="jstl"%>
<jsp:include page="Templates/metas.jsp"/>
<script type="text/javascript">
	function sendForm( ){
		
		document.getElementById('acc').value=0;
		document.forms['cotizadorForm'].submit();
		
		}

	function hideSeguro(obj){
		if(obj.value==1){
			$("#spSeguro").css("display","none");
		}else{
			$("#spSeguro").css("display","block");
		}
	}

	function calc(  ){

		var nPaq = document.getElementById('cantidad').value ;
		var unidad = document.getElementById('unidad').checked ;

		for( i = 0 ; i < nPaq ; i++ ){
			var x = i + 1 ;

			var lar = document.getElementById('largo_'+x).value ;
			var anch = document.getElementById('ancho_'+x).value ;
			var alt = document.getElementById('alto_'+x).value ;
			
			if( !unidad ){
				lar = lar * 2.54 ;
				anch = anch * 2.54 ;
				alt = alt * 2.54 ;
				$('#pk_'+x).html('lb.') ;
			}	else	{
				$('#pk_'+x).html('kg.') ;
			}

			var pVol = ( lar*anch*alt )/6000 ;
			
			$('#pv_'+x).html(pVol.toFixed(2)) ;
			document.getElementById('pesoVol_'+x).value = pVol ;			
			} 

		
		}
</script>

    <body>
        <!--[if lt IE 7]>
            <p class="chromeframe">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> or <a href="http://www.google.com/chromeframe/?redirect=true">activate Google Chrome Frame</a> to improve your experience.</p>
        <![endif]-->
		
		<jsp:include page="Templates/headerEng.jsp"/>
       
        <section id="container">
       		<!-- icono de chat -->
			<!-- <a href="#" class="ico_chat"><img alt="ico_chat" src="img/ico_chat.png"></a> -->
			<span id="node_chat_njsd" class="ico_chat"></span>
			<!-- / icono de chat -->
        <h1 class="mine_title"><img src="img/shadow_title.png" class="shadow_mineTit">CHECK THE COST</h1>
        	<p class="txt txt_gray">
        		<b>Use this tool to calculate approximate cost for the importing and delivering of your orders.</b>
        	</p>
        	<br><br>
        	<!-- AVISOS DE ERROR -->
        	<div align="center" class="txt txt_red">
        		<html:errors/>
        	</div>
        	<c:choose>
        		<c:when test="${Form.acc eq 0 }">
        		
        			<html:form action="cotizador_eng.do" method="post">
						<table class="table_reg2" width="35%">
							<tr>
								<td align="right" width="40%"><span class="txt_red">*</span>Number of pieces (packages):</td>
								<td width="60%">								
									<html:text styleClass="txt_input" size="5" property="cantidad" value="${Form.cantidad}" styleId="cantidad" onchange="sendForm();"/>
									<html:hidden property="acc" styleId="acc" value="1"/>
								</td>
							</tr>
							<tr>
								<td align="right"><span class="txt_red">*</span>Type of merchandise:</td>
								<td>
									<html:select property="tipo_mercancia" styleId="tipo_mercanciaC" onchange="return hideSeguro(this);">
										<c:set var="print" value="0"/>										
										<c:forEach items="${mercancias}" var="mercancia">
											<c:if test="${mercancia.cve_mercancia eq Form.tipo_mercancia }">
												<option selected="selected" value="${mercancia.cve_mercancia}">${mercancia.nombre_eng}</option>
												<c:set var="print" value="1"/>
											</c:if>
												<c:if test="${mercancia.cve_mercancia ne Form.tipo_mercancia }">
													<option value="${mercancia.cve_mercancia}">${mercancia.nombre_eng}</option>
												</c:if>																							
										</c:forEach>
										<c:if test="${print eq 0 }">
												<option selected="selected" value="0">Select</option>
										</c:if>
									</html:select>							
								</td>
							</tr>
							<tr>
								<td align="right">Declared value:</td>
								<td>
								<html:text styleClass="txt_input" size="10" value="${Form.valor}" property="valor"/> <span class="txt_gray">USD</span>
								</td>
							</tr>							
							<tr>
								<td align="right"><span class="txt_red">*</span>Zip Code</td>
								<td>
									<html:text styleClass="txt_input" size="10" value="${Form.cp}" property="cp"/>
								</td>
							</tr>
						</table>
						<hr>
						<h2 class="subtitle txt_red">SELECT ONE OF THE FOLLOWING OPTIONS TO REGISTER THE ACTUAL WEIGHT AND VOLUMETRIC WEIGHT OF YOUR SHIPMENT:</h2>
		        		<table class="table_reg2">
		        			<tr>
		        				<td>
		        				<c:if test="${Form.unidad eq 1 or Form.unidad eq 0 }">
		        					<input type="radio" name="unidad" id="unidad" value="1" checked>
		        				</c:if>
		        				<c:if test="${Form.unidad eq 2 }">
		        					<input type="radio" name="unidad" id="unidad" value="1" >
		        				</c:if>
		        				<span class="txt_gray">Weight in kilograms and dimensions in centimeters</span></td>
		        			</tr>
		        			<tr>
		        				<td>
		        				<c:if test="${Form.unidad eq 2 }">
		        					<input type="radio" name="unidad" value="2" checked>
		        				</c:if>
		        				<c:if test="${Form.unidad eq 1 or Form.unidad eq 0 }">
		        					<input type="radio" name="unidad" value="2">
		        				</c:if>
		        				 <span class="txt_gray">Weight in pounds and dimensions in inches</span></td>
		        			</tr>
		        		</table>
		        		
		        		<div>
			        		<c:forEach items="${paquetes }" var="paquete" varStatus="num">
				        		<!-- Paquetes  -->
				        		<p class="txt txt_red"><b>Package ${num.count }</b></p>
				        		<table class="table_reg2">
				        			<tr>
				        				<td>Weight:</td>
				        				<td><input type="text" class="txt_input" size="5" value="${paquete[0]}" id="peso_${num.count}" name="peso" onkeyup="calc();"></td>
				        				<td>Dimensional weight:</td>
				        				<td>
				        					<input type="text" class="txt_input" size="5" value="${paquete[1]}" id="largo_${num.count}" name="largo" onkeyup="calc();">
				        					<br>
				        					<small>Length</small>
				        				</td>
				        				<td>
				        					<input type="text" class="txt_input" size="5" value="${paquete[2]}" id="ancho_${num.count}" name="ancho" onkeyup="calc();">
				        					<br>
				        					<small>Width</small>
				        				</td>
				        				<td>
				        					<input type="text" class="txt_input" size="5" value="${paquete[3]}" id="alto_${num.count}" name="alto" onkeyup="calc();">
				        					<br>
				        					<small>Weight</small>
				        				</td>
				        				<td class="td_redAbs">Calculated volumetric weight: <span id="pv_${num.count}"> ${paquete[4] } </span> <span id="pk_${num.count}">kg.</span>
				        					<input type="hidden" class="txt_input" size="5" value="${paquete[4]}" name="pesoVol" id="pesoVol_${num.count}">
				        				</td>
				        			</tr>
				        		</table>
				        		<!-- Paquetes  -->
				        	</c:forEach>
		        		</div>
		        		<table class="table_reg2">
		        			<tr>
		        				<td id="spSeguro">Merchandise insurance: 
		        					<span class="txt_gray">
			        					<c:if test="${Form.seguro eq 'si' or Form.seguro eq null }">
			        						<input type="radio" name="seguro" value="si" checked> Yes &emsp;
		        						</c:if> 
		        						<c:if test="${Form.seguro eq 'no' }">
			        						<input type="radio" name="seguro" value="si"> Yes &emsp;
		        						</c:if>
		        						<c:if test="${Form.seguro eq 'no' }"> 
		        							<input type="radio" name="seguro" value="no" checked> No
		        						</c:if> 
		        						<c:if test="${Form.seguro eq 'si' or Form.seguro eq null }"> 
		        							<input type="radio" name="seguro" value="no" checked> No
		        						</c:if> 
		        					</span>
		        				</td>
		        			</tr>
		        		</table>
		        		<p class="txt txt_small txt_gray">
		        			The weight after comparing the real weight over the volumetric weight will apply for the transport quote.
		        			<br>
		        			To calculate the CIF value of your merchandise add you product value plus the freight of the US store to your Laredo, TX residence plus the transportation insurance (in case you ask for the service).
		        			<br><br>
		        			<input onclick="return sendData();" type="image" src="img/btn_calcularEng.png"> &ensp; <input onclick="document.getElementById('acc').value=2;" type="image" src="img/btn_borrarEng.png">
		        		</p>
		        		<hr>
		        		</html:form>
        				<script type="text/javascript">
		        			function sendData(){
		        				valor = document.getElementById("valorC").value;
		        				tipo = document.getElementById("tipo_mercanciaC").value;
			        			if( valor<=100 || tipo == 1 || tipo == 3 || tipo == 4 ){
			        				document.getElementById("seguroNO").checked = true;
			        				document.getElementById("seguroSI").checked = false;
				        		}
		        				document.getElementById('acc').value=1;
			        			return true;
			        		}
		        		</script>
        		</c:when>
        		<c:otherwise>
        		
        			<c:if test="${tamanio gt 0}">
	        		<h2 class="subtitle txt_red">Here is a detail quote:</h2>
	        		
	        		<c:if test="${ alerta_valor eq 'ok' }">
	        			<h2 class="subtitle txt_red">The impuestps be applied with another cup difente</h2>
	        		</c:if>
	        		
	        		<c:forEach items="${Res}" var="res">
		        		<c:if test="${ res.servicio eq 'EXPRESS' }">
		        			<table class="table_calculo" style="float: left;">
			        			<thead>
			        				<tr>
			        					<th>CONCEPT</th>
			        					<th>QUOTE</th>
			        				</tr>
			        			</thead>
			        			<tr class="alternate">
			        				<td><b>Service</b></td>
			        				<td>${res.servicio}</td>
			        			</tr>
			        			<tr>
			        				<td><b>Import taxes</b></td>
			        				<td>$ ${res.impuestos}</td>
			        			</tr>
			        			<tr class="alternate">
			        				<td><b>Handling</b></td>
			        				<td>$ ${res.manejo}</td>
			        			</tr>
			        			<tr>
			        				<td><b>Shipping</b></td>
			        				<td>$ ${res.envio}</td>
			        			</tr>
			        			<tr class="alternate">
			        				<td><b>Insurance</b></td>
			        				<td>$ ${res.seguro}</td>
			        			</tr>
			        			<tfoot>
			        				<tr>
			        					<td><b>TOTAL USD:</b></td>
			        					<td>$ ${res.total}</td>
			        				</tr>
			        			</tfoot>
			        		</table>
			        		<span class="clear"></span>
		        		</c:if>
		        		
		        		<c:if test="${ res.servicio eq 'ECOEXPRESS' && Form.tipo_mercancia ne '1' }">
		        			<table class="table_calculo" style="float: left;">
			        			<thead>
			        				<tr>
			        					<th>CONCEPT</th>
			        					<th>QUOTE</th>
			        				</tr>
			        			</thead>
			        			<tr class="alternate">
			        				<td><b>Service</b></td>
			        				<td>${res.servicio}</td>
			        			</tr>
			        			<tr>
			        				<td><b>Import taxes</b></td>
			        				<td>$ ${res.impuestos}</td>
			        			</tr>
			        			<tr class="alternate">
			        				<td><b>Handling</b></td>
			        				<td>$ ${res.manejo}</td>
			        			</tr>
			        			<tr>
			        				<td><b>Shipping</b></td>
			        				<td>$ ${res.envio}</td>
			        			</tr>
			        			<tr class="alternate">
			        				<td><b>Insurance</b></td>
			        				<td>$ ${res.seguro}</td>
			        			</tr>
			        			<tfoot>
			        				<tr>
			        					<td><b>TOTAL USD:</b></td>
			        					<td>$ ${res.total}</td>
			        				</tr>
			        			</tfoot>
			        		</table>
			        		<span class="clear"></span>
		        		</c:if>
	        		</c:forEach>
	        			        		
        		</c:if>
        		<c:if test="${tamanio eq 0}">
        		<div align="center" class="txt txt_red">
	        		No hay cotizaci&oacute;n
	        	</div>
        		</c:if>
        		
        		<p class="txt_small">
        			The final result is an approximate amount according to the data entered which could vary depending on the real weight shipment information and the calculation of taxes once merchandise has been revised on its arrival.
        			<br><br>
        			<a href="cotizador.do" ><img alt="" src="img/btn_nuevoCalculoEng.png"></a>
        		</p>
        			
        		</c:otherwise>
        	</c:choose>
        		
        		<br>
        		<p class="txt_small txt_center">
        			For more information you can contact us at <span class="txt_blue"><b>01 800</b></span> 2492400 or via email at <a href="mailto:informacion@redpost.com.mx" class="link_blue">informacion@redpost.com.mx</a>.
        		</p>
        		<br><br>
        </section>
        
		<jsp:include page="Templates/footerEng.jsp"/>
		<script type="text/javascript">
        	$(".txt_input").attr("onkeypress","return ValidNum(event)");
        </script>
        <script>calc();</script>